package com.zretc.admin.controller;


import com.zretc.admin.service.AdminService;

import com.zretc.api.pojo.SysUser;
import com.zretc.api.pojo.adminModule.Announcement;
import com.zretc.common.entity.R;
import com.zretc.common.entity.RespResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private AdminService adminService;


    //查看所有内推信息
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @GetMapping("/AllRecommendList")
    public RespResult AllRecommendList(Integer pageNum, Integer pageSize,Integer status){
        return R.success(adminService.getAllRecommend(pageNum,pageSize,status));
    }
    //查看所有活动信息
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @GetMapping("/AllActivityList")
    public RespResult AllActivityList(Integer pageNum, Integer pageSize,Integer status){
        return R.success(adminService.getAllActivity(pageNum,pageSize,status));
    }

    //查看所有博文信息
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @GetMapping("/AllBlogList")
    public RespResult AllBlogList(Integer pageNum, Integer pageSize,Integer status){
        return R.success(adminService.getAllBlog(pageNum,pageSize,status));
    }

    //审批内推
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/approvalRecommend")
    public RespResult approvalRecommend( Integer recommendId,Integer status){
        return adminService.approvalRecommend( recommendId, status);
    }
    //删除内推
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/DeleteRecommend")
    public RespResult DeleteRecommend(Integer recommendId){
        return adminService.deleteRecommend(recommendId);
    }

    //审批活动
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/approvalActivity")
    public RespResult approvalActivity(Integer activityId,Integer status){
        return adminService.approvalActivity(activityId,status);
    }

    //删除活动
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/deleteActivity")
    public RespResult deleteActivity(Integer ActivityId){
        return R.success(adminService.deleteActivity(ActivityId));
    }
    //审批博文
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/approvalBlog")
    public RespResult approvalBlog( Long BlogId, Byte status){
        return adminService.approvalBlogId(BlogId,status);
    }
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    //删除博文
    @PostMapping("/deleteBlog")
    public RespResult deleteBlog(Long BlogId){
        return R.success(adminService.deleteBlog(BlogId));
    }

    //添加公告
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/addAnno")
    public RespResult addAnnouncement(@RequestBody Announcement announcement){
        return R.success(adminService.addAnnouncement(announcement));
    }
//     删除公告
@PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/deleteAnno")
    public RespResult deleteAnnouncement(Integer announcementId){
        return R.success(adminService.delAnnouncement(announcementId));
    }
//    查看公告
@PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @GetMapping("/getAllAnno")
    public RespResult getAnnouncement(Integer pageNum, Integer pageSize,Integer is_deleted){
        return R.success(adminService.getAllAnnouncement(pageNum,pageSize, is_deleted));
    }

    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @GetMapping("/getAlluser")
    public RespResult getAllUser(Integer pageNum, Integer pageSize,String role){
        return R.success(adminService.getAlluser(pageNum,pageSize,role));

    }
    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/deleteUser")
    public RespResult deleteUser(Integer userId){
        return R.success(adminService.deleteUser(userId));
    }



    @PreAuthorize("@zr.hasAnyAuthority('system:admin:list')")
    @PostMapping("/updateUser")
    public RespResult updateUser(Integer userId,Integer role){
        return R.success(adminService.updateUser(userId,role));
    }
}
